package com.easico.activity.ui.login;

import android.app.Activity;

import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;

import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.easico.activity.GiftHomeActivity;
import com.easico.activity.HomeActivity;
import com.easico.activity.R;
import com.easico.activity.databinding.ActivityGiftLoginBinding;
import com.xuexiang.xui.XUI;

public class GiftLoginActivity extends AppCompatActivity {

    private LoginViewModel loginViewModel;
    private ActivityGiftLoginBinding binding;
    private EditText username;
    private EditText password;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.v("EASICO", "GiftLoginActivity");
        XUI.initTheme(this);
        XUI.init(getApplication());     // 初始化UI框架
        XUI.debug(true);

        setContentView(R.layout.activity_gift_login);

        binding = ActivityGiftLoginBinding.inflate(getLayoutInflater());
        // setContentView(binding.getRoot());

        loginViewModel = new ViewModelProvider(this, new LoginViewModelFactory())
                .get(LoginViewModel.class);

        final EditText usernameEditText = binding.username;
        final EditText passwordEditText = binding.password;
        final Button giftLogin = binding.login;
        final ProgressBar loadingProgressBar = binding.loading;


        /**
         * 返回主页
         */
        ImageView backHome = findViewById(R.id.backHome);
        backHome.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(GiftLoginActivity.this, HomeActivity.class);
                startActivity(intent);
                // 结束当前Activity
                finish();
            }
        });

        /**
         * 登录
         */
//        Button clickLogin = findViewById(R.id.giftLogin);
//        clickLogin.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
////                String userStr = username.getText().toString().trim();
////                String pwdStr = password.getText().toString().trim();
////                performLogin(userStr, pwdStr);
//                performLogin("admin", "123456");
//            }
//        });
    }

    private void performLogin(String username, String password) {
        Toast.makeText(this, "正在登录...", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(GiftLoginActivity.this, GiftHomeActivity.class);
        startActivity(intent);
        finish(); // 结束登录页
    }

    public void giftLogin(View v) {
        Log.v("EASICO","giftLogin正在登录...");
        // Toast.makeText(this, "正在登录...", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(GiftLoginActivity.this, GiftHomeActivity.class);
        startActivity(intent);
        // finish(); // 结束登录页
    }

}